//
//  LFBBaseViewController.m
//  LFBLoveFreshBee
//
//  Created by 丁鼎 on 16/8/18.
//  Copyright © 2016年 丁鼎. All rights reserved.
//

#import "LFBBaseViewController.h"
#import "LFBTabBar.h"
@interface LFBBaseViewController ()

@end

@implementation LFBBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    LFBTabBar *tabBar = [[LFBTabBar alloc]init];
    [self setValue:tabBar forKey:@"tabBar"];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(presentedVC) name:@"presentedVC" object:nil];
    
}

-(instancetype)init{
    
    if(self  = [super init])
    {
        [self addChildViewcontrollers];

    }
    return self;
    
}

-(void)addChildViewcontrollers{
    LFBHomeViewController *home = [[LFBHomeViewController alloc]init];
    
    [self addChildViewController:home WithImagename:@"v2_home" WithTitle:@"首页"];
    LFBFlashMarketViewController *flash = [[LFBFlashMarketViewController alloc]init];
    
    [self addChildViewController:flash WithImagename:@"v2_order" WithTitle:@"闪电超市"];

    
    LFBMyInfoViewController *myinfo = [[LFBMyInfoViewController alloc]init];
    
    [self addChildViewController:myinfo WithImagename:@"v2_my" WithTitle:@"我的"];
    
}


-(void)addChildViewController:(UIViewController *)vc WithImagename:(NSString *)imageName WithTitle:(NSString *)title{
    
    UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
    vc.title = title;
    nav.navigationBar.barTintColor = KThemeColor;
    UIImage *image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.image = image;
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"%@_r",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    [self addChildViewController:nav];
  
}


-(void)presentedVC{
    
    LFBCartViewController *cart = [[LFBCartViewController alloc]init];
    
    UINavigationController *nav  =[[UINavigationController alloc]initWithRootViewController:cart];
    
    [self presentViewController:nav animated:YES completion:nil];
    
}

@end
